﻿using CommunityToolkit.Mvvm.ComponentModel;
using CommunityToolkit.Mvvm.Input;
using CommunityToolkitMvvmDemo.Behaviors;
using CommunityToolkitMvvmDemo.Properties;
using CommunityToolkitMvvmDemo.ValidationRules;
using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.ComponentModel.DataAnnotations;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using static System.Runtime.InteropServices.JavaScript.JSType;

namespace CommunityToolkitMvvmDemo.ViewModels
{
    public  partial   class ValidationRuleViewModel : ObservableObject,ITextValidationError
    {
        [ObservableProperty]
        private int param1;

        [ObservableProperty]
        private int param2;

        [ObservableProperty]
        private int result;

        [ObservableProperty]
        private string errorMsg = string.Empty;

        [ObservableProperty]
        public ObservableCollection<string> errors  = new ObservableCollection<string>();

        [ObservableProperty]
        private int textBoxValue;

        [RelayCommand]
        void Calcul()
        {
            ErrorMsg = "";
            if (Errors.Count > 0)
            {
                ErrorMsg = "参数错误，原因：" + Errors[0];
                return;
            }
            Result = Param1+Param2;
        }
    }
}
